﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.Slaughter
{
    public class SlaughteringenterpriseHandler : IRequestHandler<SlaughteringenterpriseCommond, Rulst>
    {
        private readonly IbaseRpository<slaughterMess> _Slaughtermess;

        public SlaughteringenterpriseHandler(IbaseRpository<slaughterMess> slaughtermess)
        {
            _Slaughtermess = slaughtermess;
        }

        public async Task<Rulst> Handle(SlaughteringenterpriseCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };




            var list =_Slaughtermess.Query().Where(x=>x.ProDuctionBasicid==request.ProDuctionBasicid).FirstOrDefault();

            if (list != null) 
            {
                list.BossName = request.BossName;
                      list.Provinceid=request.Provinceid;
                      list.Cityid=request.Cityid;
                      list.countyid=request.countyid;
                      list.SetupTime=request.SetupTime;
                      list.BossIntroMess=request.BossIntroMess;
                      list.ProDuctionBasicid=request.ProDuctionBasicid;

             query.data=   _Slaughtermess.update(list);
                query.MSG = "修改成功";
            }
            else
            {

                var result = new slaughterMess()
                {
                    BossName=request.BossName,
                    Provinceid = request.Provinceid,
                    Cityid = request.Cityid,
                    countyid = request.countyid,
                    SetupTime = request.SetupTime,
                    BossIntroMess = request.BossIntroMess,
                    ProDuctionBasicid = request.ProDuctionBasicid,

                  
                };
              query.data=  _Slaughtermess.Add(result);

                query.MSG = "添加成功";


            }



            return query;



        }
    }
}
